﻿/*++

Copyright (c) 2011 Rainr Corporation

Module Name:

	Rainr.Utilities.IO.FileUtility

Abstract:

	文件工具类

Author:

	Zhou Junyu (Rainr)    2011-01-01

Revision History:
  
--*/

using System.IO;

namespace Rainr.Utilities.IO
{
    /// <summary>
    /// 文件工具类
    /// </summary>
    public class FileUtility
    {
        /// <summary>
        /// 获取文件扩展名不带 [.]
        /// </summary>
        /// <returns>文件扩展名不带[.]</returns>
        public static string GetFileExtension(string fileName)
        {
            string extension = string.Empty;
            if (!string.IsNullOrEmpty(fileName))
            {
                int lastd = fileName.LastIndexOf('.');
                if (lastd > 0 && lastd < fileName.Length - 1)
                {
                    extension = fileName.Substring(lastd + 1);
                }
            }
            return extension;
        }

        /// <summary>
        /// 获得文件的短名称（不带扩展名）
        /// </summary>
        /// <param name="fileName">文件全名</param>
        /// <returns>文件名称（不带扩展名）</returns>
        public static string GetFileShortName(string fileName)
        {
            string shortName = string.Empty;
            if (!string.IsNullOrEmpty(fileName))
            {
                int lastd = fileName.LastIndexOf('.');
                int lastg = fileName.LastIndexOf('\\');
                if (lastd > 0 && lastg < lastd)
                {
                    if (lastg < 0) lastg = 0;
                    shortName = fileName.Substring(lastg, lastd);
                }
            }
            return shortName;
        }
    }
}
